﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Hi_Baidu.Packet.InPacket
{
    class DeleteFriendReplyPacket : BaseInPackage
    {
        public DeleteFriendReplyPacket(InPackage inpackage) : base(inpackage)
        {
        }

        public override void InitPackage()
        {
            int Offset = 0;
            //用户名长度
            byte[] UsernameLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, UsernameLength, 0, 4);
            Offset += 4;
            //用户名长度
            byte[] Username = new byte[BitConverter.ToInt32(UsernameLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, Username, 0, Username.Length);
            Offset += Username.Length;
            //好友长度
            byte[] FriendsLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, FriendsLength, 0, 4);
            Offset += 4;
            //好友
            byte[] Friends = new byte[BitConverter.ToInt32(FriendsLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, Friends, 0, Friends.Length);
            Offset += Friends.Length;
            //删除状态
            byte[] DeleteState = new byte[1];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, DeleteState, 0, 1);
            Offset += 1;

            this.DIC_CONTENT.Add("USERNAME", Username);
            this.DIC_CONTENT.Add("FRIENDUSERNAME", Friends);
            this.DIC_CONTENT.Add("DELETESTATE", DeleteState);
        }

        /// <summary>
        ///     获得好友用户名
        /// </summary>
        /// <returns></returns>
        public String GetFriendName()
        {
            return Encoding.Default.GetString(this.DIC_CONTENT["FRIENDUSERNAME"]);
        }

        /// <summary>
        ///     得到删除状态
        /// </summary>
        /// <returns></returns>
        public bool GetDeleteState()
        {
            return BitConverter.ToBoolean(this.DIC_CONTENT["DELETESTATE"], 0);
        }
    }
}
